package ee.ttu.rakarh.model.data.dao;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import ee.ttu.rakarh.model.data.entities.ItemType;
import ee.ttu.rakarh.model.data.entities.TypeAttribute;
import ee.ttu.rakarh.util.HibernateUtil;

public class TypeAttributeDAOImpl implements TypeAttributeDAO {

	private static final Logger LOG = Logger.getLogger(TypeAttributeDAOImpl.class);

	@Override
	public Collection<TypeAttribute> getTypeAttributesByType(ItemType itemType) {
		List<TypeAttribute> typeAttributes = new ArrayList<TypeAttribute>();
		Session session = null;
		try {
			LOG.info("id=" + itemType.getId());
			session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			Criteria crit = session.createCriteria(TypeAttribute.class);
			typeAttributes = crit.add(Restrictions.eq("itemType", itemType)).list();
		}
		catch (Exception e) {
			LOG.error(e);
		}finally{			
			//session.close();
		}
		return typeAttributes;
	}

}
